package examples.collections;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Random;

import org.apache.commons.lang3.RandomStringUtils;

import examples.collections.model.Book;

public class Util {

	public static Random random = new Random();
	
	public static ArrayList<String> generateArrayList(int size) {
		ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < size; i++) {
			list.add(RandomStringUtils.randomAscii(10));
		}
		return list;
	}

	public static LinkedList<String> generateLinkedList(int size) {
		LinkedList<String> list = new LinkedList<String>();
		for (int i = 0; i < size; i++) {
			list.add(RandomStringUtils.randomAscii(10));
		}
		return list;
	}

	public static Book generateRandomBook(long id) {
		Book book = new Book(id, RandomStringUtils.randomAscii(20));
		book.setAuthor(RandomStringUtils.randomAscii(20));
		book.setCategory(Book.Category.values()[random.nextInt(Book.Category.values().length)]);
		book.setEdition(Integer.toString(random.nextInt(5)));
		book.setPublicationDate(new Date());

		return book;
	}
	
	public static Book[] generateRandomBookArray(int count) {
		Book[] books = new Book[count];
		for (int i = 0; i < count; i++) {
			books[i] = generateRandomBook(i);
		}
		return books;
	}
	
	public static ArrayList<Book> generateRandomBookArrayList(int count) {
		ArrayList<Book> books = new ArrayList<Book>();
		for (int i = 0; i < count; i++) {
			books.add(generateRandomBook(i));
		}
		return books;
	}
	
	public static LinkedList<Book> generateRandomBookLinkedList(int count) {
		LinkedList<Book> books = new LinkedList<Book>();
		for (int i = 0; i < count; i++) {
			books.add(generateRandomBook(i));
		}
		return books;
	}
	
	public static HashSet<Book> generateRandomBookHashSet(int count) {
		HashSet<Book> books = new HashSet<Book>();
		for (int i = 0; i < count; i++) {
			books.add(generateRandomBook(i));
		}
		return books;
	}
	
	public static HashMap<String, Book> generateRandomBookHashMap(int count) {
		HashMap<String, Book> bookMap = new HashMap<String, Book>();
		for (int i = 0; i < count; i++) {
			Book book = generateRandomBook(i);
			bookMap.put(book.getTitle(), book);
		}
		return bookMap;
	}

}
